#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 200100;
int a[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int ans = 0;
		int n;
		scanf("%d",&n);
		for(int i = 1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		int min = a[n];
		for(int i =n;i>=1;i--)
		{
			if(a[i]>min)
			{
				ans++;
			}
			else min = a[i];
		}
		printf("%d\n",ans);
	}
}
